package com.company.project.rabbitMQ;

import cn.hutool.core.util.StrUtil;
import com.company.project.email.entity.EmailEntity;
import com.company.project.email.service.EmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;

/**
 * @author ZYF
 * @date 2021/9/2 17:04
 */
@Component
@RabbitListener(queues = {"email"})
@Slf4j
public class EmailConsumer {

    @Resource
    EmailService emailService;

    @RabbitHandler
    public void reviceMessage(String message) throws MessagingException, UnsupportedEncodingException {
      log.info("====================接收到的消息"+message);
       EmailEntity  emailEntity = emailService.getById(message);
       if(null != emailEntity){
           emailService.sendMail(emailEntity);
       }

    }
}
